package com.itheima.hw.test3;

import java.io.*;
import java.util.Arrays;

public class Test {

    public static void main(String[] args) {
        try(
                BufferedReader br = new BufferedReader(
                        new FileReader("day11_io\\src\\com\\itheima\\hw\\test3\\question.txt"));

                BufferedWriter bw = new BufferedWriter(
                        new FileWriter("day11_io\\src\\com\\itheima\\hw\\test3\\result.txt"));

                PrintWriter pw = new PrintWriter(bw);
                ) {
            //1.定义输入输出流
            String line = null;

            while((line = br.readLine()) != null){
                //2.读取文件中的每行数据
                System.out.println( line );
                //3.处理每行的数据
                String[] results = line.split("\\D");//非数字：\\D
                double rs = 0.0;
                if(line.contains("+")){
                    rs = Double.parseDouble(results[0]) + Double.parseDouble(results[1]);
                    pw.println(results[0] + " + " + results[1] + " = " + rs);
                }else if(line.contains("-")){
                    rs = Double.parseDouble(results[0]) - Double.parseDouble(results[1]);
                    pw.println(results[0] + " - " + results[1] + " = " + rs);
                }else if(line.contains("*")){
                    rs = Double.parseDouble(results[0]) * Double.parseDouble(results[1]);
                    pw.println(results[0] + " * " + results[1] + " = " + rs);
                }else{
                    rs = Double.parseDouble(results[0]) / Double.parseDouble(results[1]);
                    pw.println(results[0] + " / " + results[1] + " = " + rs);
                }
            }

            System.out.println("计算完毕！");

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
